<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="<%=basePath %>">
    <title>图书管理系统——编辑图书</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">

    <input type="hidden" id="id" name="id" disabled="disabled" class="layui-input">

    <div class="layui-form-item">
        <label class="layui-form-label">图书编号</label>
        <div class="layui-input-inline">
            <input type="text" id="no" name="no" lay-verify="required" placeholder="请输入图书编号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图书名称</label>
        <div class="layui-input-inline">
            <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入图书名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图书类型</label>
        <div class="layui-input-inline">
            <select id="type" name="type" lay-verify="required">
                <option value="文学类">文学类</option>
                <option value="历史类">历史类</option>
                <option value="编程类">编程类</option>
                <option value="法律类">法律类</option>
                <option value="其他">其他</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-inline">
            <input type="text" id="author" name="author" lay-verify="required" placeholder="请输入作者" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-inline">
            <input type="number" id="price" name="price" lay-verify="required" placeholder="请输入价格" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">语言</label>
        <div class="layui-input-inline">
            <input type="text" id="language" name="language" lay-verify="required" placeholder="请输入语言" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
               value="确认添加">
    </div>
</div>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="./layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: './layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: '/booksUpdate',
                data: field,
                type: 'post',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 0) {
                        //添加成功
                        layer.msg('编辑成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 3000
                        }, function () {
                            parent.layui.table.reload("LAY-app-books-list");//重载表格
                            parent.layer.close(index);//关闭当前的iframe
                        });
                    } else if (result.code == 1) {
                        layer.open({
                            title: '提示'
                            , content: result.msg
                        });
                    }
                }
            })
        });
    })
</script>
</body>
</html>
